package composite;

import java.util.List;
import java.util.ArrayList;

/**
 * @author LAD
 * 
 */
public class Employee {
	private String name;
	private String dept;
	private int salary;
	private List<Employee> subodinates;
	private int level;
	
	/**
	 * Employee's 3 params constructors
	 * @param name: Employee's name 
	 * @param dept: Employee's department
	 * @param sal: Employee's salaray
	 */
	public Employee(String name, String dept, int sal){
		this.name = name;
		this.dept = dept;
		this.salary = sal;
		this.subodinates = new ArrayList<Employee>();
	}
	
	/**
	 * Constructors
	 * @param name: Employee's name 
	 * @param dept: Employee's department
	 * @param sal: Employee's salaray
	 * @param level: Employee's level in organization
	 */
	public Employee(String name, String dept, int sal, int level) {
		this.name = name;
		this.dept = dept;
		this.salary = sal;
		this.subodinates = new ArrayList<Employee>();
		this.level = level;
	}
	
	/**
	 * Sets the level of the employee (Starting from 1)
	 * @param level: the Employee's level
	 */
	public void setLevel(int level){
		this.level = level;
	}
	
	/**
	 * Gets the level of the employee
	 * @return Employee's level
	 */
	public int getLevel(){
		return this.level;
	}
	
	/**
	 * Removes an employee from this employee's list of subodinates
	 * @param The employee to be removed
	 */
	public void remove(Employee employee){
		subodinates.remove(employee);
	}
	
	/**
	 * Gets the list of this employee's subodinates 
	 * @return List of subodinates
	 */
	public List<Employee> getsubodinates(){
		return subodinates;
	}
	
	/**
	 * Adds the employee to this employee's list of subodinates
	 * @param The employee to be added
	 */
	public void add(Employee employee){
		employee.setLevel(this.level + 1);
		subodinates.add(employee);
	}	
	
	/**
	 * Override the Object's toString() method
	 */
	@Override
	public String toString() {
		StringBuilder stringBuilder = new StringBuilder();
		for (int i = 0; i < this.level; i++) {
			stringBuilder.append("\t");
		}
		stringBuilder.append("-- Employee: [Name: " + name + ", dept: " + dept + ", salary: " + salary + " ]\n");
		for (Employee employee : subodinates) {
			stringBuilder.append(employee.toString());
		}
		return stringBuilder.toString();
	}
}	
